##Chapter5Master.r
###master script for creating all Tables and Figures 
###in original analysis included in Chapter 5 of:
###Enos, Ryan D.  2017. The Space Between Us:
### Social Geography and Politics
####RdE December 2017

rm(list = ls())

##load packages
library(ggplot2)
library(apsrtable)
library(scales)

##clustered standard errors function
cl   <- function(dat,fm, cluster){
  require(sandwich, quietly = TRUE)
  require(lmtest, quietly = TRUE)
  M <- length(unique(cluster))
  N <- length(cluster)
  K <- fm$rank
  dfc <- (M/(M-1))*((N-1)/(N-K))
  uj  <- apply(estfun(fm),2, function(x) tapply(x, cluster, sum));
  uj = uj[complete.cases(uj),]  
  
  vcovCL <- dfc*sandwich(fm, meat=crossprod(uj)/N)
  return(vcovCL) }

source('TableA23FiguresA2A3_5_6.r')
source('TableA24.r')
source('TableA25.r')